<template>
  <div class="ifreg">
    <div class="massagebox" v-if="!ploy">
      <h1>注册成功，等待跳转</h1>
      <p class="dengdai">正在前往登陆页面......</p>
      <p class="href">若无反应，<a href="/">点此跳转</a></p>
    </div>
    <div class="massagebox" v-if="ploy">
      <h1>此账号已被注册</h1>
      <p class="dengdai">正在前往登陆页面......</p>
      <p class="href">若无反应，<a href="/login">点此跳转</a></p>
    </div>
  </div>
</template>
<style>
.ifreg {
  width: 1200px;
  margin: 0 auto;
  position: relative;
  display: flex;
}
.ifreg .massagebox {
  width: 100%;
  height: 300px;
  border: 1px solid #c8f27e91;
  background-color: #daff9891;
  border-radius: 10px;
  margin-top: 10px;
}
.ifreg .massagebox h1 {
  margin-top: 10px;
  text-align: center;
}
.ifreg .massagebox .dengdai {
  text-align: center;
  margin-top: 50px;
}
.ifreg .massagebox .href {
  text-align: center;
  flex-direction: column-reverse;
  justify-content: space-between;
  line-height: 300px;
}
.ifreg .massagebox .href a {
  color: #00f;
  text-decoration: bottom;
}
</style>
<script>
export default {
  data() {
    return {
      //验证用户是否被注册
      ploy: true,
    };
  },
  mounted() {
    let url = decodeURIComponent(window.location.search);
    let Url = url.slice(1);
    let url1 = Url.split("&");
    // console.log(url1);
    let uname = url1[0].split("=");
    let upwd = url1[1].split("=");
    let uemail = url1[2].split("=");
    // console.log(uemail);
    let arr = [];
    arr.push(uname[1]), arr.push(upwd[1], arr.push(uemail[1]));
    // console.log(arr);
    this.axios.post("/regName", "username=" + arr[0]).then((res) => {
      let data = res.data.code;
      //   如果用户名已存在
      if (data == 3000) {
        // 显示账号已被注册
        this.ploy = true;
        window.setTimeout(() => {
          window.location.replace("/login");
        }, 3000);
      } else {
        this.ploy = false;
        this.axios
          .post(
            "/register",
            "username=" + arr[0] + "&upwd=" + arr[2] + "&uemail=" + arr[1]
          )
          .then((res) => {
            let data = res.data;
            // console.log(data);
            if (data.code == 3002) {
              window.setTimeout(() => {
                window.location.replace("/login");
              }, 3000);
              // this.$router.push('/index/home');
            }
          });
      }
    });
  },
};
</script>